package k2_oop.p8_javaUtil.demo02;

import java.util.*;

public class ShuffleNums {

    public static int[] shuffle(int[] nums){

        Random random = new Random();

        int tmpIndex = 0;
        int tmpNum = 0;

        for (int i = 0; i < nums.length; i++) {

            while(true){
                tmpIndex = random.nextInt(nums.length);
                if(tmpIndex!=i){
                    break;
                }
            }

            tmpNum = nums[i];
            nums[i] = nums[tmpIndex];
            nums[tmpIndex] = tmpNum;

        }

        return nums;
    }


    public static void main(String[] args) {
        int[] nums = {1,2,3,4,5,6,7,8,9,10};

        System.out.println(Arrays.toString(shuffle(nums)));
    }
}
